<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   使用GPU和Theano加速深度学习  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/20365.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466461211: Accept with keywords: (title(0.333333333333):社区,数盟,深度学习, topn(0.433333333333):社区,感知器,数盟,深度学习,行业资讯,神经网络,时间,损失,数据挖掘,精度,文件,学习曲线,文章,Python,标签,模型,职业规划,硬件,基础架构,图像,数据,函数,卷积,主目录,矩阵,代码,网络,测试数据,灰度,神经元).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    使用GPU和Theano加速深度学习
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    使用GPU和Theano加速深度学习 | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,65] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/20365.html">
          使用GPU和Theano加速深度学习
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          3,061 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech" rel="category tag">
          文章
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <p>
        出处：
        <a href="http://www.csdn.net/article/2015-08-07/2825415">
         csdn
        </a>
       </p>
       <p>
        GPU因其浮点计算和矩阵运算能力有助于加速深度学习是业界的共识，Theano是主流的深度学习Python库之一，亦支持GPU，然而Theano入门较难，Domino的这篇博文介绍了如何使用GPU和Theano加速深度学习，使用更简单的基于Theano的
        <a href="https://github.com/dnouri/nolearn">
         Nolearn
        </a>
        库。教程由多层感知器及卷积神经网络，由浅入深，是不错的入门资料。
       </p>
       <h3>
        基于Python的深度学习
       </h3>
       <p>
        实现神经网络算法的Python库中，最受欢迎的当属Theano。然而，Theano并不是严格意义上的神经网络库，而是一个Python库，它可以实现各种各样的数学抽象。正因为如此，Theano有着陡峭的学习曲线，所以我将介绍基于Theano构建的有更平缓的学习曲线的两个神经网络库。
       </p>
       <p>
        第一个库是
        <a href="https://github.com/Lasagne/Lasagne">
         Lasagne
        </a>
        。该库提供了一个很好的抽象，它允许你构建神经网络的每一层，然后堆叠在彼此的顶部来构建一个完整的模型。尽管这比Theano显得更好，但是构建每一层，然后附加在彼此顶部会显得有些冗长乏味，所以我们将使用
        <a href="https://github.com/dnouri/nolearn">
         Nolearn
        </a>
        库，它在Lasagne库上提供了一个类似
        <a href="http://scikit-learn.org/stable/">
         Scikit-Learn
        </a>
        风格的API，能够轻松地构建多层神经网络。
       </p>
       <p>
        <b>
         延伸阅读
        </b>
        ：
        <a href="http://dataunion.org/20365.html">
         从Theano到Lasagne：基于Python的深度学习的框架和库
        </a>
       </p>
       <p>
        由于这些库默认使用的不是Domino硬件，所以你需要创建一个requirements.txt文件，该文件内容如下：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b55b732564511" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          -e git://github.com/Theano/Theano.git#egg=Theano
-e git://github.com/lasagne/lasagne.git#egg=lasagne
nolearn==0.5.0
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b55b732564511-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b55b732564511-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b55b732564511-3">
               3
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b55b732564511-1">
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-i">
                e
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                git
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-c">
                //github.com/Theano/Theano.git#egg=Theano
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b55b732564511-2">
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-i">
                e
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                git
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-c">
                //github.com/lasagne/lasagne.git#egg=lasagne
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b55b732564511-3">
               <span class="crayon-v">
                nolearn
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-cn">
                0.5.0
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0035 seconds] -->
       <p>
       </p>
       <h3>
        配置Theano
       </h3>
       <p>
        现在，在我们导入Lasagne库和Nolearn库之前，首先我们需要配置Theano，使其可以使用GPU硬件。要做到这一点，我们需要在我们的工程目录中新建一个.theanorc文件，该文件内容如下：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b56c714589827" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          [global] device = gpu floatX = float32 [nvcc] fastmath = True
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b56c714589827-1">
               1
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b56c714589827-1">
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-m">
                global
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                device
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                gpu
               </span>
               <span class="crayon-v">
                floatX
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                float32
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                nvcc
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                fastmath
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                True
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0013 seconds] -->
       <p>
        这个.theanorc文件必须放置在主目录中。在你的本地计算机上，这个操作可以手工完成，但我们不能直接访问Domino机器的主目录，所以我们需要使用下面的代码将文件移到它的主目录中：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b573057800633" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          import os import shutil destfile = "/home/ubuntu/.theanorc" open(destfile,
        'a').close() shutil.copyfile(".theanorc", destfile)
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b573057800633-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b573057800633-2">
               2
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b573057800633-1">
               <span class="crayon-e">
                import
               </span>
               <span class="crayon-e">
                os
               </span>
               <span class="crayon-e">
                import
               </span>
               <span class="crayon-e">
                shutil
               </span>
               <span class="crayon-v">
                destfile
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "/home/ubuntu/.theanorc"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                open
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                destfile
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b573057800633-2">
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'a'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                close
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                shutil
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                copyfile
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                ".theanorc"
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                destfile
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0015 seconds] -->
       <p>
        上面的代码会在主目录创建了一个空的.theanorc文件，然后复制我们项目目录下的.theanorc文件内容到该文件中。
       </p>
       <p>
        将硬件切换到GPU后，我们可以来做一下测试，使用Theano文档中提供的测试代码来看看Theano是否能够检测到GPU。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b57a095501695" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          from theano import function, config, shared, sandbox  
import theano.tensor as T  
import numpy  
import time

vlen = 10 * 30 * 768  # 10 x #cores x # threads per core  
iters = 1000

rng = numpy.random.RandomState(22)  
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))  
f = function([], T.exp(x))  
print f.maker.fgraph.toposort()  
t0 = time.time()  
for i in xrange(iters):  
    r = f()
t1 = time.time()  
print 'Looping %d times took' % iters, t1 - t0, 'seconds'  
print 'Result is', r  
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):  
    print 'Used the cpu'
else:  
    print 'Used the gpu'
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b57a095501695-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b57a095501695-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b57a095501695-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b57a095501695-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b57a095501695-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b57a095501695-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b57a095501695-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b57a095501695-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b57a095501695-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b57a095501695-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b57a095501695-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b57a095501695-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b57a095501695-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b57a095501695-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b57a095501695-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b57a095501695-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b57a095501695-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b57a095501695-18">
               18
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b57a095501695-19">
               19
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b57a095501695-20">
               20
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b57a095501695-21">
               21
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b57a095501695-22">
               22
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b57a095501695-1">
               <span class="crayon-e">
                from
               </span>
               <span class="crayon-e">
                theano
               </span>
               <span class="crayon-e">
                import
               </span>
               <span class="crayon-t">
                function
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                config
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                shared
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                sandbox
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b57a095501695-2">
               <span class="crayon-e">
                import
               </span>
               <span class="crayon-v">
                theano
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                tensor
               </span>
               <span class="crayon-st">
                as
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                T
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b57a095501695-3">
               <span class="crayon-e">
                import
               </span>
               <span class="crayon-e">
                numpy
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b57a095501695-4">
               <span class="crayon-e">
                import
               </span>
               <span class="crayon-e">
                time
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b57a095501695-5">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b57a095501695-6">
               <span class="crayon-v">
                vlen
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                10
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                30
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                *
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                768
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                # 10 x #cores x # threads per core
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b57a095501695-7">
               <span class="crayon-v">
                iters
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1000
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b57a095501695-8">
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b57a095501695-9">
               <span class="crayon-v">
                rng
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                numpy
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                random
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                RandomState
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                22
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b57a095501695-10">
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                shared
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                numpy
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                asarray
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                rng
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                rand
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                vlen
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                config
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                floatX
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b57a095501695-11">
               <span class="crayon-v">
                f
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                function
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                T
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                exp
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b57a095501695-12">
               <span class="crayon-i">
                print
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                f
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                maker
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                fgraph
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                toposort
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b57a095501695-13">
               <span class="crayon-v">
                t0
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                time
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                time
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b57a095501695-14">
               <span class="crayon-st">
                for
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                in
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                xrange
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                iters
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b57a095501695-15">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                r
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                f
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b57a095501695-16">
               <span class="crayon-v">
                t1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                time
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                time
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b57a095501695-17">
               <span class="crayon-i">
                print
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'Looping %d times took'
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                iters
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                t1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                t0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'seconds'
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b57a095501695-18">
               <span class="crayon-i">
                print
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'Result is'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                r
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b57a095501695-19">
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                numpy
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                any
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-e">
                isinstance
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                op
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                T
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                Elemwise
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                for
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                x
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                in
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                f
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                maker
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                fgraph
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                toposort
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b57a095501695-20">
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                print
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'Used the cpu'
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b57a095501695-21">
               <span class="crayon-st">
                else
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b57a095501695-22">
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                print
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'Used the gpu'
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0289 seconds] -->
       <p>
        如果Theano检测到GPU，上面的函数运行时间应该需要0.7秒，并且输出“Used the gpu”。否则，整个过程将需要2.6秒的运行时间，同时输出“Used the cpu”’。如果输出的是后一个，那么你肯定是忘记将硬件切换到GPU了。
       </p>
       <h3>
        数据集
       </h3>
       <p>
        对于这个项目，我们将使用CIFAR-10图像数据集，它来自10个不同的类别，包含了60000个32×32大小的彩色图像。
       </p>
       <p>
        <img src="http://img.ptcms.csdn.net/article/201508/07/55c4c708b7519_middle.jpg?_=63005"/>
       </p>
       <p>
        幸运的是，这些数据属于
        <a href="https://en.wikipedia.org/wiki/Pickle_(Python)">
         pickled
        </a>
        格式，所以我们可以使用辅助函数来加载数据，将每个文件加载到NumPy数组中并返回训练集（Xtr），训练集标签（Ytr），测试集（Xte）以及测试集标签（Yte）。下列代码归功于
        <a href="http://cs231n.stanford.edu/">
         Stanford’s CS231n
        </a>
        课程的工作人员。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b582565440395" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          import cPickle as pickle  
import numpy as np  
import os

def load_CIFAR_file(filename):  
    '''Load a single file of CIFAR'''
    with open(filename, 'rb') as f:
        datadict= pickle.load(f)
        X = datadict['data']
        Y = datadict['labels']
        X = X.reshape(10000, 3, 32, 32).transpose(0,2,3,1).astype('float32')
        Y = np.array(Y).astype('int32')
        return X, Y


def load_CIFAR10(directory):  
    '''Load all of CIFAR'''
    xs = []
    ys = []
    for k in range(1,6):
        f = os.path.join(directory, "data_batch_%d" % k)
        X, Y = load_CIFAR_file(f)
        xs.append(X)
        ys.append(Y)
    Xtr = np.concatenate(xs)
    Ytr = np.concatenate(ys)
    Xte, Yte = load_CIFAR_file(os.path.join(directory, 'test_batch'))
    return Xtr, Ytr, Xte, Yte
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-18">
               18
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-19">
               19
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-20">
               20
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-21">
               21
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-22">
               22
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-23">
               23
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-24">
               24
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-25">
               25
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-26">
               26
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b582565440395-27">
               27
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b582565440395-28">
               28
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-1">
               <span class="crayon-e">
                import
               </span>
               <span class="crayon-e">
                cPickle
               </span>
               <span class="crayon-st">
                as
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                pickle
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-2">
               <span class="crayon-e">
                import
               </span>
               <span class="crayon-e">
                numpy
               </span>
               <span class="crayon-st">
                as
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                np
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-3">
               <span class="crayon-e">
                import
               </span>
               <span class="crayon-e">
                os
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-4">
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-5">
               <span class="crayon-e">
                def
               </span>
               <span class="crayon-e">
                load_CIFAR_file
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                filename
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                ''
               </span>
               <span class="crayon-s">
                'Load a single file of CIFAR'
               </span>
               <span class="crayon-s">
                ''
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                with
               </span>
               <span class="crayon-e">
                open
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                filename
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'rb'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                as
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                f
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                datadict
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                pickle
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                load
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                f
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-9">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                X
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                datadict
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'data'
               </span>
               <span class="crayon-sy">
                ]
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-10">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                datadict
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'labels'
               </span>
               <span class="crayon-sy">
                ]
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-11">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                X
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                X
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                reshape
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                10000
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                32
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                32
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                transpose
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                astype
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'float32'
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-12">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                np
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-t">
                array
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                astype
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'int32'
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-13">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                X
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                Y
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-14">
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-15">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-16">
               <span class="crayon-e">
                def
               </span>
               <span class="crayon-e">
                load_CIFAR10
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                directory
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-17">
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                ''
               </span>
               <span class="crayon-s">
                'Load all of CIFAR'
               </span>
               <span class="crayon-s">
                ''
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-18">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                xs
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ]
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-19">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ys
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ]
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-20">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                for
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                k
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                in
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                range
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                6
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-21">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                f
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                os
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                path
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                join
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                directory
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "data_batch_%d"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                k
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-22">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                X
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                load_CIFAR_file
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                f
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-23">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                xs
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                append
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-24">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                ys
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                append
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                Y
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-25">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Xtr
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                np
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                concatenate
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                xs
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-26">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Ytr
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                np
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                concatenate
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                ys
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b582565440395-27">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Xte
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Yte
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                load_CIFAR_file
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                os
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                path
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                join
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                directory
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'test_batch'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b582565440395-28">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Xtr
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Ytr
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Xte
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Yte
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0126 seconds] -->
       <p>
       </p>
       <h3>
        多层感知器
       </h3>
       <p>
        多层感知器是一种最简单的神经网络模型。该模型包括一个输入层数据，一个施加一些数学变换的隐藏层，以及一个输出层用来产生一个标签（不管是分类还是回归，都一样）。
       </p>
       <p>
        <img src="http://img.ptcms.csdn.net/article/201508/07/55c4c7348d168.jpg"/>
       </p>
       <p>
        图片来源：http://dms.irb.hr/tutorial/tut_nnets_short.php
       </p>
       <p>
        在我们使用训练数据之前，我们需要把它的灰度化，把它变成一个二维矩阵。此外，我们将每个值除以255然后减去0.5。当我们对图像进行灰度化时，我们将每一个（R,G,B）元组转换成0到255之间的浮点值）。通过除以255，可以标准化灰度值映射到[0,1]之间。接下来，我们将所有的值减去0.5，映射到区间[ -0.5，0.5 ]上。现在，每个图像都由一个1024维的数组表示，每一个值都在- 0.5到0.5之间。在训练分类网络时，标准化你的输入值在[-1,1]之间是个很常见的做法。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b58b638633284" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          X_train_flat = np.dot(X_train[...,:3], [0.299, 0.587, 0.114]).reshape(X_train.shape[0],-1).astype(np.float32)  
X_train_flat = (X_train_flat/255.0)-0.5  
X_test_flat = np.dot(X_test[...,:3], [0.299, 0.587, 0.114]).reshape(X_test.shape[0],-1).astype(np.float32)  
X_test_flat = (X_test_flat/255.0)-.5
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b58b638633284-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b58b638633284-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b58b638633284-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b58b638633284-4">
               4
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b58b638633284-1">
               <span class="crayon-v">
                X_train_flat
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                np
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                dot
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_train
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                0.299
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.587
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.114
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                reshape
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_train
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                shape
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                astype
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                np
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                float32
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b58b638633284-2">
               <span class="crayon-v">
                X_train_flat
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_train_flat
               </span>
               <span class="crayon-o">
                /
               </span>
               <span class="crayon-cn">
                255.0
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                0.5
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b58b638633284-3">
               <span class="crayon-v">
                X_test_flat
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                np
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                dot
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_test
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                0.299
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.587
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.114
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                reshape
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_test
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                shape
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                astype
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                np
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                float32
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b58b638633284-4">
               <span class="crayon-v">
                X_test_flat
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_test_flat
               </span>
               <span class="crayon-o">
                /
               </span>
               <span class="crayon-cn">
                255.0
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-cn">
                5
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0047 seconds] -->
       <p>
        使用nolearn的API，我们可以很容易地创建一个输入层，隐藏层和输出层的多层感知器。hidden_num_units = 100表示我们的隐藏层有100个神经元，output_num_units = 10则表示我们的输出层有10个神经元，并与标签一一对应。输出前，网络使用
        <a href="https://en.wikipedia.org/wiki/Softmax_function">
         softmax
        </a>
        函数来确定最可能的标签。迭代50次并且设置verbose=1来训练模型，最后会输出每次迭代的结果及其需要的运行时间。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b593034837041" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          net1 = NeuralNet( layers = [ ('input', layers.InputLayer), ('hidden',
                layers.DenseLayer), ('output', layers.DenseLayer), ], #layers parameters:
                input_shape = (None, 1024), hidden_num_units = 100, output_nonlinearity
                = softmax, output_num_units = 10, #optimization parameters: update = nesterov_momentum,
                update_learning_rate = 0.01, update_momentum = 0.9, regression = False,
                max_epochs = 50, verbose = 1, )
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b593034837041-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b593034837041-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b593034837041-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b593034837041-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b593034837041-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b593034837041-6">
               6
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b593034837041-1">
               <span class="crayon-v">
                net1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                NeuralNet
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'input'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                InputLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'hidden'
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b593034837041-2">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                DenseLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'output'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                DenseLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                #layers parameters:
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b593034837041-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                input_shape
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                None
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1024
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                hidden_num_units
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                100
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                output_nonlinearity
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b593034837041-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                softmax
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                output_num_units
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                10
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                #optimization parameters: update = nesterov_momentum,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b593034837041-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                update_learning_rate
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.01
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                update_momentum
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.9
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                regression
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                False
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b593034837041-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                max_epochs
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                50
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                verbose
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0043 seconds] -->
       <p>
        从侧面来说，这个接口使得它很容易建立深层网络。如果我们想要添加第二个隐藏层，我们所需要做的就是把它添加到图层参数中，然后在新增的一层中指定多少个神经元。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b599676902648" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          net1 = NeuralNet( layers = [ ('input', layers.InputLayer), ('hidden1',
                    layers.DenseLayer), ('hidden2', layers.DenseLayer), #Added Layer Here ('output',
                    layers.DenseLayer), ], #layers parameters: input_shape = (None, 1024),
                    hidden1_num_units = 100, hidden2_num_units = 100, #Added Layer Params Here
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b599676902648-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b599676902648-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b599676902648-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b599676902648-4">
               4
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b599676902648-1">
               <span class="crayon-v">
                net1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                NeuralNet
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'input'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                InputLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'hidden1'
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b599676902648-2">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                DenseLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'hidden2'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                DenseLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                #Added Layer Here ('output',
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b599676902648-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                DenseLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                #layers parameters: input_shape = (None, 1024),
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b599676902648-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                hidden1_num_units
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                100
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                hidden2_num_units
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                100
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                #Added Layer Params Here
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0028 seconds] -->
       <p>
        现在，正如我前面提到的关于Nolearn类似Scikit-Learn风格的API，我们可以用fit函数来拟合神经网络。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b5a0459909114" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          net1.fit(X_train_flat, y_train)
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b5a0459909114-1">
               1
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b5a0459909114-1">
               <span class="crayon-v">
                net1
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                fit
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_train_flat
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                y_train
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0006 seconds] -->
       <p>
        当网络使用GPU训练时，我们可以看到每次迭代时间通常需要0.5秒。
       </p>
       <p>
        <img src="http://img.ptcms.csdn.net/article/201508/07/55c4c7d3f2745_middle.jpg?_=35653"/>
       </p>
       <p>
        另一方面，当Domino的硬件参数设置为XX-Large（32 core, 60 GB RAM），每次迭代时间通常需要1.3秒。
       </p>
       <p>
        <img src="http://img.ptcms.csdn.net/article/201508/07/55c4c7eeb3c4d_middle.jpg?_=63183"/>
       </p>
       <p>
        通过GPU训练的神经网络，我们可以看到在训练网络上大约提速了3倍。正如预期的那样，使用GPU训练好的神经网络和使用CPU训练好的神经网络产生了类似的结果。两者产生了相似的测试精度（约为41%）以及相似的训练损失。
       </p>
       <p>
        通过下面代码，我们可以在测试数据上测试网络：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b5a6777615148" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          y_pred1 = net1.predict(X_test_flat)  
print "The accuracy of this network is: %0.2f" % (y_pred1 == y_test).mean()
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b5a6777615148-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5a6777615148-2">
               2
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b5a6777615148-1">
               <span class="crayon-v">
                y_pred1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                net1
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                predict
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_test_flat
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5a6777615148-2">
               <span class="crayon-i">
                print
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "The accuracy of this network is: %0.2f"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                y_pred1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                y_test
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                mean
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0013 seconds] -->
       <p>
        最后，我们在测试数据上得到的精度为41%。
       </p>
       <h3>
        卷积网络
       </h3>
       <p>
        卷积神经网络是一种更为复杂的神经网络结构，它的一个层中的神经元和上一层的一个子集神经元相连。结果，卷积往往会池化每个子集的输出。
       </p>
       <p>
        <img src="http://img.ptcms.csdn.net/article/201508/07/55c4c853a53f0_middle.jpg?_=64399"/>
       </p>
       <p>
        图片来源：
        <a href="http://colah.github.io/posts/2014-07-Conv-Nets-Modular/">
         http://colah.github.io/posts/2014-07-Conv-Nets-Modular/
        </a>
       </p>
       <p>
        卷积神经网络在企业和
        <a href="http://jeffreydf.github.io/diabetic-retinopathy-detection/" target="_blank">
         Kaggle 竞赛
        </a>
        中很受欢迎，因为它能灵活地学习不同的问题并且易扩展。
       </p>
       <p>
        同样，在我们建立卷积神经网络之前，我们首先必须对数据进行灰度化和变换。这次我们会保持图像32×32的大小不变。此外，我已经修改了矩阵的行顺序，所以每个图像现在被表示为（color，x，y）格式。跟之前一样，我将特征的每个值除以255，再减去0.5，最后将数值映射到区间（-1，1）。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b5ad192626628" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          X_train_2d = np.dot(X_train[...,:3], [0.299, 0.587, 0.114]).reshape(-1,1,32,32).astype(np.float32)  
X_train_2d = (X_train_2d/255.0)-0.5  
X_test_2d = np.dot(X_test[...,:3], [0.299, 0.587, 0.114]).reshape(-1,1,32,32).astype(np.float32)  
X_train_2d = (X_train_2d/255.0)-0.5
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b5ad192626628-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5ad192626628-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5ad192626628-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5ad192626628-4">
               4
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b5ad192626628-1">
               <span class="crayon-v">
                X_train_2d
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                np
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                dot
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_train
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                0.299
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.587
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.114
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                reshape
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                32
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                32
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                astype
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                np
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                float32
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5ad192626628-2">
               <span class="crayon-v">
                X_train_2d
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_train_2d
               </span>
               <span class="crayon-o">
                /
               </span>
               <span class="crayon-cn">
                255.0
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                0.5
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5ad192626628-3">
               <span class="crayon-v">
                X_test_2d
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                np
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                dot
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_test
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                0.299
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.587
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.114
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                reshape
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                32
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                32
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                astype
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                np
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                float32
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5ad192626628-4">
               <span class="crayon-v">
                X_train_2d
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_train_2d
               </span>
               <span class="crayon-o">
                /
               </span>
               <span class="crayon-cn">
                255.0
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                0.5
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0047 seconds] -->
       <p>
        现在我们可以构造卷积神经网络了。该网络由输入层，3个卷积层，3个2×2池化层，200个神经元隐藏层以及最后的输出层构成。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b5b4305232795" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          net2 = NeuralNet(  
    layers = [
        ('input', layers.InputLayer),
        ('conv1', layers.Conv2DLayer),
        ('pool1', layers.MaxPool2DLayer),
        ('conv2', layers.Conv2DLayer),
        ('pool2', layers.MaxPool2DLayer),
        ('conv3', layers.Conv2DLayer),
        ('pool3', layers.MaxPool2DLayer),
        ("hidden4", layers.DenseLayer),
        ("output", layers.DenseLayer),
        ],
        #layer parameters:
        input_shape = (None, 1, 32, 32),
        conv1_num_filters = 16, conv1_filter_size = (3, 3), pool1_pool_size = (2,2),
        conv2_num_filters = 32, conv2_filter_size = (2, 2) , pool2_pool_size =  (2,2),
        conv3_num_filters = 64, conv3_filter_size = (2, 2), pool3_pool_size = (2,2),
        hidden4_num_units = 200,
        output_nonlinearity = softmax,
        output_num_units = 10,

        #optimization parameters:
        update = nesterov_momentum,
        update_learning_rate = 0.015,
        update_momentum = 0.9,
        regression = False,
        max_epochs = 5,
        verbose = 1,
        )
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-18">
               18
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-19">
               19
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-20">
               20
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-21">
               21
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-22">
               22
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-23">
               23
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-24">
               24
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-25">
               25
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-26">
               26
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-27">
               27
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5b4305232795-28">
               28
              </div>
              <div class="crayon-num" data-line="crayon-57686c0f5b5b4305232795-29">
               29
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-1">
               <span class="crayon-v">
                net2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                NeuralNet
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-2">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'input'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                InputLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'conv1'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                Conv2DLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'pool1'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                MaxPool2DLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'conv2'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                Conv2DLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'pool2'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                MaxPool2DLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'conv3'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                Conv2DLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-9">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'pool3'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                MaxPool2DLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-10">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "hidden4"
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                DenseLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-11">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "output"
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                layers
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                DenseLayer
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-12">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-13">
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                #layer parameters:
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-14">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                input_shape
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                None
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                32
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                32
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-15">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                conv1_num_filters
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                16
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                conv1_filter_size
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                3
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                pool1_pool_size
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-16">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                conv2_num_filters
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                32
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                conv2_filter_size
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                pool2_pool_size
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-17">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                conv3_num_filters
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                64
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                conv3_filter_size
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                pool3_pool_size
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-18">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                hidden4_num_units
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                200
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-19">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                output_nonlinearity
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                softmax
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-20">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                output_num_units
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                10
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-21">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-22">
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                #optimization parameters:
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-23">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                update
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                nesterov_momentum
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-24">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                update_learning_rate
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.015
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-25">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                update_momentum
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.9
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-26">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                regression
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                False
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-27">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                max_epochs
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                5
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5b4305232795-28">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                verbose
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ,
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c0f5b5b4305232795-29">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0106 seconds] -->
       <p>
        接着，我们再次使用fit函数来拟合模型。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b5bb266860390" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          net2.fit(X_train_2d, y_train)
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b5bb266860390-1">
               1
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b5bb266860390-1">
               <span class="crayon-v">
                net2
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                fit
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_train_2d
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                y_train
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0008 seconds] -->
       <p>
        与多层感知器相比，卷积神经网络的训练时间会更长。使用GPU来训练，大多数的迭代需要12.8s来完成，然而，卷积神经网络验证损失约为63%，超过了验证损失为40%的多层感知器。也就是说，通过卷积层和池化层的结合，我们可以提高20%的精度。
       </p>
       <p>
        <img src="http://img.ptcms.csdn.net/article/201508/07/55c4c8e8cfceb_middle.jpg?_=51353"/>
       </p>
       <p>
        在只有Domino的XX-大型硬件层的CPU上，每个训练周期大概需要177秒完成，接近于3分钟。也就是说，用GPU训练，训练时间提升了大约15倍。
       </p>
       <p>
        <img src="http://img.ptcms.csdn.net/article/201508/07/55c4c931d2715_middle.jpg?_=32899"/>
       </p>
       <p>
        和前面一样，我们可以看到在CUP上训练的卷积神经网络与GPU上训练的卷积神经网络有着类似的结果，相似的验证精度与训练损失。
       </p>
       <p>
        此外，当我们在测试数据上测试卷积神经网络时，我们得到了61%的精度。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c0f5b5c2663298917" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          y_pred2 = net2.predict(X_test_2d)  
print "The accuracy of this network is: %0.2f" % (y_pred2 == y_test).mean()
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c0f5b5c2663298917-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c0f5b5c2663298917-2">
               2
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c0f5b5c2663298917-1">
               <span class="crayon-v">
                y_pred2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                net2
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                predict
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                X_test_2d
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c0f5b5c2663298917-2">
               <span class="crayon-i">
                print
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "The accuracy of this network is: %0.2f"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                y_pred2
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                y_test
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                mean
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0015 seconds] -->
       <p>
        建立卷积神经网络的所有代码都可以在ConvolutionNN.py这个
        <a href="https://app.dominodatalab.com/LeJit/GPU_Example/view/ConvolutionNN.py" target="_blank">
         文件
        </a>
        中找到。
       </p>
       <p>
        最后，正如你所看到的，使用GPU训练的深度神经网络会加快运行加速，在这个项目中它提升的速度在3倍到15倍之间。无论是在工业界还是学术界，我们经常会使用多个GPU，因为这会大大减少深层网络训练的运行时间，通常能从几周下降至几天。
       </p>
       <p>
        原文链接：
        <a href="http://blog.dominodatalab.com/gpu-computing-and-deep-learning/" target="_blank">
         Faster deep learning with GPUs and Theano
        </a>
        （译者/刘帝伟 审校/刘翔宇、朱正贵 责编/周建丁）
       </p>
       <p>
        <b>
         关于译者：
        </b>
        <a href="http://blog.csdn.net/dream_angel_z">
         刘帝伟
        </a>
        ，中南大学软件学院在读研究生，关注机器学习、数据挖掘及生物信息领域。
       </p>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/20824.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/t018630756a7e263b33-300x165.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20824.html" rel="bookmark" title="如何判断一笔交易是否属于欺诈？你只是需要一点数据挖掘">
         如何判断一笔交易是否属于欺诈？你只是需要一点数据挖掘
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20820.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/1-300x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20820.html" rel="bookmark" title="人们对Python在企业级开发中的10大误解">
         人们对Python在企业级开发中的10大误解
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20811.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/t0133fcacae8523307b_副本-300x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20811.html" rel="bookmark" title="大神亲传：26条深度学习的金科玉律！">
         大神亲传：26条深度学习的金科玉律！
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20808.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/640.webp-11-300x137.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20808.html" rel="bookmark" title="我们是如何在一张地图上表现86万个数据的">
         我们是如何在一张地图上表现86万个数据的
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <!-- If comments are open, but there are no comments. -->
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F20365.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/20365.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/20365.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>